#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <vector>
using namespace std;
const int N = 100010;
int dp[N][2];
int main() {
    unordered_map<int, int> hsh;
    vector<int> v;
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i)
    {
        int tmp; cin >> tmp;
        if (hsh.count(tmp) == 0)
            v.push_back(tmp);
        hsh[tmp]++;
    }
    sort(v.begin(), v.end());
    // cout << v.size() << endl;
    for (int i = 1; i <= v.size(); ++i)
    {
        if (i == 1)
            dp[1][1] = v[0] * hsh[v[0]];
        else
        {
            int pre = v[i - 2], now = v[i - 1];
            if (pre == now - 1)
            {
                // cout << pre << ' ' << now << ' ' << hsh[now] << endl;
                dp[i][1] = dp[i - 1][0] + now * hsh[now];
                dp[i][0] = max(dp[i - 1][1], dp[i - 1][0]);
            }
            else {
                dp[i][0] = max(dp[i - 1][0], dp[i - 1][1]);
                dp[i][1] = dp[i][0] + now * hsh[now];
            }
        }
    }
    cout << max(dp[v.size()][1], dp[v.size()][0]) << endl;
}
// 64 位输出请用 printf("%lld")